using DG.Tweening;
using DG.Tweening.Plugins.Core.PathCore;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DotweenPath : MonoBehaviour
{
    public Transform cube;
    public Transform pathRoot;
    public PathType pathType;
    private Path path;
    private Vector3[] points;
    private void Start()
    {
        points = new Vector3[3];
        for (int i = 0; i < pathRoot.childCount; i++)
        {
            points[i] = pathRoot.GetChild(i).position;
        }
    }

    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.Space))
            DoPathAnim();
    }

    private void DoPathAnim()
    {
        path = new Path(pathType, points, 10);
        Tween tween = cube.DOPath(path, 1f, PathMode.Sidescroller2D);
        tween.ForceInit();
        Debug.Log(tween.PathLength());
        if (path.wpLengths != null)
        {
            var totalLength = 0f;
            for (int i = 0; i < path.wpLengths.Length; i++)
            {
                totalLength += path.wpLengths[i];
            }
            Debug.LogError(totalLength);
        }
    }
}
